<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <title>认识VueComponent</title>
        <!-- 引入Vue -->
        <script type="text/javascript" src="../../js/vue.js"></script>
    </head>
    <body>
        <!-- 准备好一个容器-->
        <div id="demo"></div>

        <script type="text/javascript">
            // 创建Person组件
            const Person = Vue.extend({
                name:'Person',
                template:`
                    <div style="background-color:skyblue;padding:20px">
                        <h2>姓名：{{name}}</h2>
                        <button @click="showName">提示名字</button>
                    </div>
                `,
                data() {
                    return {
                        name:'张三'
                    }
                },
                methods: {
                    showName(){
                        console.log('小弟',this)
                        alert(this.name)
                    }
                },
            })

            const School = Vue.extend({})

            const Order = Vue.extend({})

            const Hello = Vue.extend({})
            
            new Vue({
                el:'#demo',
                template:`
                    <div style="background-color:gray;padding:20px">
                        <h1 @click="showSname">欢迎来到{{sname}}</h1>
                        <Person/>
                        <Person/>
                    </div>
                `,
                components:{Person},
                data(){
                    return {
                        sname:'尚硅谷'
                    }
                },
                methods: {
                    showSname(){
                        console.log('大哥',this)
                        alert(this.sname)
                    }
                },
            })
        
        </script>
    </body>
</html>